package hms.inventory;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;

import hms.database.DAO;
import hms.database.DAOnoGUI;
import hms.database.DBRowObject;
import hms.employees.Employee;
import hms.permissions.PermissionSet;

/**
 * <h2>Class Overview</h2>
 * 
 * An InventoryEntry is an object used and owned by a hotel. InventoryEntry is
 * composed of the following: inv_entry_name, category, vendor, size, quantity,
 * and price.
 * 
 * @author Akilah McIntyre
 */
public class InventoryEntry extends DBRowObject {

	private int inv_entry_id; // Unique Identifier of InventoryEntry
	private String inv_entry_name; // Name of InventoryEntry
	private CatalogItem catalogItem; // Name of inventory entry
	private ItemCategory itemCategory; // InventoryEntry category
	private Vendor vendor; // Vendor supplying item
	private InvColor color; // InventoryEntry color
	private Size size; // InventoryEntry Size
	private double price; // InventoryEntry price
	private int quantity; // Number of item in inventory

	/**
	 * 
	 * @param inv_entry_id
	 *            Unique Identifier of InventoryEntry
	 * @param catalogItem
	 *            Name of item
	 * @param itemCategory
	 *            InventoryEntry category
	 * @param vendor
	 *            Vendor supplying InventoryEntry
	 * @param color
	 *            InventoryEntry String
	 * @param size
	 *            InventoryEntry String
	 * @param price
	 *            InventoryEntry Price
	 * @param quantity
	 *            Number of item in inventory
	 */
	public InventoryEntry(int itemid, CatalogItem catalogItem,
			ItemCategory icat, Vendor vendor, InvColor color, Size size,
			double price, int quantity) {
		super(itemid);
		setInvEntryName(genInvEntryName());
		setCatalogItem(catalogItem);
		setVendor(vendor);
		setItemCategory(icat);
		setColor(color);
		setSize(size);
		setPrice(price);
		setQuantity(quantity);
	}

	public String getDebugString() {
		String str = "inv_entry_id: "
				+ (new Integer(getInvEntryId())).toString();
		str += "\n inv_entry_name: " + getInvEntryName();
		str += "\n item_name: " + getCatalogItem();
		str += "\n item_category: " + getItemCategory();
		str += "\n color: " + getColor();
		str += "\n vendor: " + getVendor();
		str += "\n size: " + getSize();
		str += "\n price: $" + getPrice();
		str += "\n quantity: " + getQuantity();
		return str;
	}

	@Override
	public String toString() {
		String str = (new Integer(getInvEntryId())).toString();
		str += ": " + getInvEntryName();
		return str;
	}

	/**
	 * 
	 * @param inv_entry_id
	 *            Unique Identifier of InventoryEntry
	 * @param catalogItem
	 *            Name of item
	 */
	public InventoryEntry(int itemid, CatalogItem catalogItem) {
		super(itemid);
		setInvEntryName(genInvEntryName());
		setCatalogItem(catalogItem);
		setPrice(0);
		setQuantity(0);
	}

	/**
	 * 
	 * @param inv_entry_id
	 *            Unique Identifier of InventoryEntry
	 */
	public InventoryEntry(int itemid) {
		super(itemid);
		setInvEntryName(genInvEntryName());
		setCatalogItem(new CatalogItem(-1, "New Item"));
		setPrice(0);
		setQuantity(0);
	}

	/**
	 * 
	 * @param inv_entry_id
	 *            Unique Identifier of InventoryEntry
	 * @param inv_entry_name
	 *            Name of item
	 */
	public InventoryEntry(CatalogItem catalogItem) {
		super();
		setInvEntryName(genInvEntryName());
		setCatalogItem(catalogItem);
		setPrice(0);
		setQuantity(0);
	}

	public InventoryEntry() {
		super();
		setInvEntryName(genInvEntryName());
		setCatalogItem(new CatalogItem(-1, "New Item"));
		setPrice(0);
		setQuantity(0);
	}

	private String genInvEntryName() {
		return "Entry #"
				+ new Long(Calendar.getInstance().getTimeInMillis()).toString();
	}

	/**
	 * Returns the inv_entry_name of an InventoryEntry
	 * 
	 * @return the inv_entry_name of an InventoryEntry
	 */
	public String getInvEntryName() {
		return inv_entry_name;
	}

	/**
	 * Sets the inv_entry_name of an InventoryEntry
	 * 
	 * @param inv_entry_name
	 *            the inv_entry_name of an InventoryEntry
	 */
	public void setInvEntryName(String inv_entry_name) {
	
	if(inv_entry_name == null || inv_entry_name ==""){
		setInvEntryName(genInvEntryName());	
	}else
	{
		this.inv_entry_name = inv_entry_name;
	}
}
	/**
	 * @return the catalogItem
	 */
	public CatalogItem getCatalogItem() {
		return catalogItem;
	}

	/**
	 * @param catItem
	 *            the catalogItem to set
	 */
	public void setCatalogItem(CatalogItem catItem) {
		this.catalogItem = catItem;
	}

	/**
	 * Returns the category of an InventoryEntry
	 * 
	 * @return the category of an InventoryEntry
	 */
	public ItemCategory getItemCategory() {
		return itemCategory;
	}

	/**
	 * Sets the category of an InventoryEntry
	 * 
	 * @param itemCategory
	 *            the category of an InventoryEntry
	 */
	public void setItemCategory(ItemCategory catItem) {
		this.itemCategory = catItem;
	}

	/**
	 * Returns the vendor of an InventoryEntry
	 * 
	 * @return the vendor of an InventoryEntry
	 */
	public Vendor getVendor() {
		return vendor;
	}

	/**
	 * Sets the vendor of an InventoryEntry
	 * 
	 * @param vendor2
	 *            the vendor of an InventoryEntry
	 */
	public void setVendor(Vendor vendor2) {
		this.vendor = vendor2;
	}

	/**
	 * Returns the color of an InventoryEntry
	 * 
	 * @return the color of an InventoryEntry
	 */
	public InvColor getColor() {
		return color;
	}

	/**
	 * Sets the color of an InventoryEntry
	 * 
	 * @param color2
	 *            the brand of an InventoryEntry
	 */
	public void setColor(InvColor color2) {
		this.color = color2;
	}

	/**
	 * Returns the size of an InventoryEntry
	 * 
	 * @return the size of an InventoryEntry
	 */
	public Size getSize() {
		return size;
	}

	/**
	 * Sets the size of an InventoryEntry
	 * 
	 * @param size2
	 *            the size of an InventoryEntry
	 */
	public void setSize(Size size2) {
		this.size = size2;
	}

	/**
	 * Returns the price of an InventoryEntry
	 * 
	 * @return the price of an InventoryEntry
	 */
	public double getPrice() {
		return price;
	}

	/**
	 * Returns the price of an InventoryEntry
	 * 
	 * @return the price of an InventoryEntry
	 */
	public void setPrice(double price) {
		this.price = price;
	}

	/**
	 * Returns the quantity of an InventoryEntry
	 * 
	 * @return the quantity of an InventoryEntry
	 */
	public int getQuantity() {
		return quantity;
	}

	/**
	 * Sets the quantity of an InventoryEntry
	 * 
	 * @param quantity
	 *            the brand of an InventoryEntry
	 */
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	/**
	 * Returns the unique identifier of an InventoryEntry
	 * 
	 * @return the unique identifier of an InventoryEntry
	 */
	public int getInvEntryId() {
		return this.inv_entry_id;
	}

	/**
	 * Sets the unique identifier of an InventoryEntry
	 * 
	 * @param inv_entry_id
	 *            unique identifier of an InventoryEntry
	 */
	public void setInvEntryId(int inv_entry_id) {
		this.inv_entry_id = inv_entry_id;
	}

	/*
	 * SELECT INV_ENTRY_ID, INV_ENTRY_NAME, PRICE, QUANTITY, ITEM_NAME_ID,
	 * ITEM_NAME, VENDOR_ID, VENDOR_NAME, SIZE_ID, SIZE_NAME, COLOR_ID,
	 * COLOR_NAME, ITEM_CATEGORY_ID, ITEM_CATEGORY_NAME FROM VW_INVENTORY_ITEMS
	 */
	@Override
	protected String[] getFieldNames() {
		String[] out = new String[6];
		out[0] = "ITEM_CATEGORY_ID";
		out[1] = "VENDOR_ID";
		out[2] = "COLOR_ID";
		out[3] = "SIZE_ID";
		out[4] = "PRICE";
		out[5] = "QUANTITY";
		return out;
	}

	@Override
	protected void loadPreparedStatement(PreparedStatement stmt)
			throws SQLException {
		// TODO Auto-generated method stub

	}

	@Override
	protected String getUniqueIdentifierFieldName() {
		return "INV_ENTRY_ID";
	}

	@Override
	protected String getTableName() {
		return "INVENTORY";
	}

	/*
	 * SELECT INV_ENTRY_ID, INV_ENTRY_NAME, PRICE, QUANTITY, ITEM_NAME_ID,
	 * ITEM_NAME, VENDOR_ID, VENDOR_NAME, SIZE_ID, SIZE_NAME, COLOR_ID,
	 * COLOR_NAME, ITEM_CATEGORY_ID, ITEM_CATEGORY_NAME FROM VW_INVENTORY_ITEMS
	 */
	@Override
	protected void loadFromDatabase(ResultSet rs) throws SQLException {

		/*
		 * this.inv_entry_name = rs.getString("INV_ENTRY_ID"); this.catalogItem
		 * = rs.getString("ITEM_NAME"); this.color = rs.getString("COLOR_NAME");
		 * this.itemCategory = rs.getString("ITEM_CATEGORY_NAME"); this.price =
		 * rs.getDouble("PRICE"); this.quantity = rs.getInt("QUANTITY");
		 * this.vendor = rs.getString("VENDOR_NAME");
		 */
	}

	@Override
	protected boolean allowDuplicateRows() {
		return false;
	}

}
